//
//  ManagerGoodViewController.m
//  ShoppingExperience
//
//  Created by LiYinDi on 15-6-2.
//  Copyright (c) 2015年 RuiBen. All rights reserved.
//

#import "ManagerGoodViewController.h"
#import "ManagerGoodTableViewCell.h"
#import "GuideListTableViewCell.h"
#import "UpYun.h"
#import "UIImageView+WebCache.h"
#import "EGORefreshTableHeaderView.h"
#import "FPNumberPadView.h"
#import "CaptureViewController.h"
#import "PassImageDelegate.h"
#import "FilterViewController.h"
@interface ManagerGoodViewController ()<EGORefreshTableHeaderDelegate,FPNumberPadViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,PassImageDelegate,FilterViewControllerDelegate>
{
    FilterViewController *filterVC;
    EGORefreshTableHeaderView *_refreshHeaderView;
    BOOL _reloading;
    
    NSUInteger _productPageIndex;
    NSUInteger _productTotalCount;
    NSUInteger _productTotalPage;
    
    NSMutableArray *managerNumArray;
  //  NSMutableArray *managerNumberArray;
    NSMutableArray *managerStatusArray;
    NSMutableArray *managerMinGramArray;
    NSMutableArray *managerMaxGramArray;
    NSMutableArray *managerMinAmountArray;
    NSMutableArray *managerMaxAmountArray;
    NSMutableArray *managerGuideNameArray;
    NSMutableArray *managerDateArray;
    NSMutableArray *managerProductNameArray;
    
    //addManagerViewContainer
    BOOL isOpened;
    NSMutableArray *guideCodeArray;
    NSMutableArray *guideNameArray;
    
    NSMutableArray *styleCodeArray;
    NSMutableArray *styleNameArray;
    NSString *guideCodeStr;
    NSString *styleCodeStr;
    
    NSMutableArray *demandCodeArray;
    NSMutableArray *demandNameArray;
    NSMutableArray *selectDemandCodeArray;
    
   // NSMutableArray *selectePictureArray;
     NSMutableArray *upYunImageArray;
    BOOL isLoad;
    
    NSInteger imageBtnTag;
    UITextField *inputTextField;
    
    NSMutableArray *filterTypeCodeArray ;
    NSMutableArray *inputFilterCodeArray;
    NSMutableArray *inputMinResultFilterNameArray;
    NSMutableArray *inputMaxResultFilterNameArray;
    NSMutableArray *selectFilterCodeArray;
    NSMutableArray *selectFilterNameArray;
    NSMutableArray *selectCustomTimeArray ;
    NSMutableArray *customTimeFilterTypeCodeArray ;
    NSString *startTimeStr;
    NSString *endTimeStr;

  }
- (void)reloadTableViewDataSource;
- (void)doneLoadingTableViewData;
//@property (nonatomic) UIImagePickerController *imagePickerController;
@end

@implementation ManagerGoodViewController
-(void)viewWillAppear:(BOOL)animated
{
    if (isLoad==NO) {
//        _addNewManagerBtn.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1] CGColor];
//        _addNewManagerBtn.layer.borderWidth= 1.0f;
//        _addNewManagerBtn.layer.cornerRadius=3;
        [_addNewManagerBtn addTarget:self action:@selector(addNewManagerBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [self initManagerList];
        [self initAddManagerViewContainer];
        [self initManagerDetail];
        [self initOrderFilterView];
        _imageViewContainer.hidden=YES;
        _productPageIndex=0;
        [self loadProductNextPage:_productPageIndex];

    }

}
-(void)initOrderFilterView
{
    inputFilterCodeArray=[NSMutableArray array];
    inputMinResultFilterNameArray=[NSMutableArray array];
    inputMaxResultFilterNameArray=[NSMutableArray array];
    filterTypeCodeArray=[NSMutableArray array];
    customTimeFilterTypeCodeArray=[NSMutableArray array];
    selectFilterCodeArray=[NSMutableArray array];
    selectFilterNameArray=[NSMutableArray array];
    selectCustomTimeArray=[NSMutableArray array];
    
    startTimeStr=@"";
    endTimeStr=@"";
    
    [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:80.0f/255.0f green:80.0f/255.0f blue:80.0f/255.0f alpha:1.0f]];
    [_orderFilterImage setImage:[UIImage imageNamed:@"shaixuandingdan_.png"]];
    // [_orderFilterViewContainer bringSubviewToFront:_resetFilterBtn];
    
    _orderFilterBtn.layer.borderColor=[[UIColor colorWithRed:220.0f/255.0f green:220.0f/255.0f blue:220.0f/255.0f alpha:1] CGColor];
    _orderFilterBtn.layer.borderWidth= 1.0f;
    _orderFilterBtn.layer.cornerRadius=4;
    
    [_orderFilterBtn addTarget:self action:@selector(orderFilterBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
}
-(void)orderFilterBtnClick
{
    if (filterVC.view!=nil) {
        
        [filterVC removeFromParentViewController];
        [filterVC.view removeFromSuperview];
        
    }
    filterVC=[[FilterViewController alloc] init];
    filterVC.delegate=self;
    filterVC.docTypeStr=@"DCount";
    filterVC.selectCustomTimeArray=[NSMutableArray arrayWithArray:selectCustomTimeArray];
    filterVC.startTimeStr=startTimeStr;
    filterVC.endTimeStr=endTimeStr;
    // NSLog(@"selectFilterNameArray=22222======%@",selectFilterNameArray);
    filterVC.selectFilterNameArray=[NSMutableArray arrayWithArray:selectFilterNameArray];
    filterVC.view.frame = CGRectMake(0,
                                     0,
                                     self.view.bounds.size.width,
                                     self.view.bounds.size.height);
    
    [self addChildViewController:filterVC];
    [self.view addSubview:filterVC.view];

}
-(void)confirmFilterBtnClick:(NSMutableArray *)commonFilterTypeCodeArray commonSelectFilterCodeArray:(NSMutableArray *)commonSelectFilterCodeArray commonInputFilterCodeArray:(NSMutableArray *)commonInputFilterCodeArray commonInputMinResultFilterNameArray:(NSMutableArray *)commonInputMinResultFilterNameArray commonInputMaxResultFilterNameArray:(NSMutableArray *)commonInputMaxResultFilterNameArray commonCustomTimeFilterTypeCodeArray:(NSMutableArray *)commonCustomTimeFilterTypeCodeArray commonSelectCustomTimeArray:(NSMutableArray *)commonSelectCustomTimeArray commonSelectFilterNameArray:(NSMutableArray *)commonSelectFilterNameArray  commonStartTimeStr:(NSString *)commonStartTimeStr commonEndTimeStr:(NSString *)commonEndTimeStr isDefault:(NSString *)isDefault
{
    
    if ([isDefault isEqualToString:@"Y"]) {
        //  NSLog(@"_isDefault0000===%@",isDefault);
        [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:80.0f/255.0f green:80.0f/255.0f blue:80.0f/255.0f alpha:1.0f]];
        [_orderFilterImage setImage:[UIImage imageNamed:@"shaixuandingdan_.png"]];
    }
    else{
        // NSLog(@"_isDefault1111===%@",isDefault);
        [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:203.0f/255.0f green:164.0f/255.0f blue:67.0f/255.0f alpha:1.0f]];
        [_orderFilterImage setImage:[UIImage imageNamed:@"yishaixuan_.png"]];
    }
    
    filterTypeCodeArray=commonFilterTypeCodeArray;
    selectFilterCodeArray=commonSelectFilterCodeArray;
    inputFilterCodeArray=commonInputFilterCodeArray;
    inputMinResultFilterNameArray=commonInputMinResultFilterNameArray;
    inputMaxResultFilterNameArray=commonInputMaxResultFilterNameArray;
    customTimeFilterTypeCodeArray=commonCustomTimeFilterTypeCodeArray;
    selectCustomTimeArray=commonSelectCustomTimeArray;
    selectFilterNameArray=commonSelectFilterNameArray;
    
    startTimeStr=commonStartTimeStr;
    endTimeStr=commonEndTimeStr;
    
    [managerNumArray removeAllObjects];
    [managerStatusArray removeAllObjects];
    [managerMinGramArray removeAllObjects];
    [managerMaxGramArray removeAllObjects];
    [managerMinAmountArray removeAllObjects];
    [managerMaxAmountArray removeAllObjects];
    [managerGuideNameArray removeAllObjects];
    [managerProductNameArray removeAllObjects];
    // [managerGuideNameArray addObject:[[managerListArray objectAtIndex:i] objectForKey:@"UserName"]];
    [managerDateArray removeAllObjects];
    
    _productPageIndex=0;
    [self loadProductNextPage:_productPageIndex];
    
}

-(void)initManagerList
{
    _searchProductTextField.text=@"";
   managerNumArray=[NSMutableArray array];
   managerStatusArray=[NSMutableArray array];
  // managerNumberArray=[NSMutableArray array];
   managerMinGramArray=[NSMutableArray array];
   managerMaxGramArray=[NSMutableArray array];
   managerMinAmountArray=[NSMutableArray array];
   managerMaxAmountArray=[NSMutableArray array];
   managerGuideNameArray=[NSMutableArray array];
   managerDateArray=[NSMutableArray array];
   managerProductNameArray=[NSMutableArray array];
}
-(void)initManagerDetail
{
   
    CGRect viewFrame=_managerDetailViewContainer.frame;
    viewFrame.origin.y=768;
    _managerDetailViewContainer.frame=viewFrame;
    
    [_managerDetailAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_managerDetailAlphaView addTarget:self action:@selector(managerDetailAlphaViewClick) forControlEvents:UIControlEventTouchUpInside];
}
-(void)managerDetailAlphaViewClick
{
    [_searchProductTextField resignFirstResponder];
    [_minGramTextField resignFirstResponder];
    [_maxGramTextField resignFirstResponder];
    [_minAmountTextField resignFirstResponder];
    [_maxAmountTextField resignFirstResponder];
    [_remarkTextView resignFirstResponder];
    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect viewFrame=_managerDetailViewContainer.frame;
         viewFrame.origin.y=768;
         _managerDetailViewContainer.frame=viewFrame;
     }completion:^(BOOL finished) {
         
     }];
}
-(void)addNewManagerBtnClick
{
    [_searchProductTextField resignFirstResponder];
    _guideNameLabel.text=[Global getGuideNameStr];
    
    guideCodeStr=[Global getGuideCodeStr];
    imageBtnTag=10000;
      // [selectePictureArray removeAllObjects];
    CGRect frame0=_addPictureButton.frame;
    frame0.origin.x=16;
    frame0.origin.y=10;
    _addPictureButton.frame=frame0;
    for (UIView *v in _pictureView.subviews) {
        if (v.tag!=90) {
            
            [v removeFromSuperview];
        }
        
    }
    CGRect viewFrame=_pictureView.frame;
    viewFrame.size.height=118;
    _pictureView.frame=viewFrame;

    CGRect viewFrame0=_pictureViewLineLabel.frame;
    viewFrame0.origin.y= _pictureView.frame.size.height-1;
    _pictureViewLineLabel.frame=viewFrame0;
    CGRect viewFrame1=_remarkViewContainer.frame;
    viewFrame1.origin.y=_pictureView.frame.origin.y+_pictureView.frame.size.height+15;
    _remarkViewContainer.frame=viewFrame1;
    
    CGRect viewFrame2=_saveBtn.frame;
    viewFrame2.origin.y=_remarkViewContainer.frame.origin.y+_remarkViewContainer.frame.size.height+20;
    _saveBtn.frame=viewFrame2;

    
    [self requestTags];
    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect viewFrame=_addManagerViewContainer.frame;
         viewFrame.origin.y=0;
         _addManagerViewContainer.frame=viewFrame;
     }completion:^(BOOL finished) {
         
     }];

}
-(void)initAddManagerViewContainer
{
    FPNumberPadView *numberPadView = [[FPNumberPadView alloc] initWithFrame:CGRectMake(0, 0, 948, 340)];
    numberPadView.FPNumberPaddelegate=self;
    numberPadView.textField = _minGramTextField;
    
    FPNumberPadView *numberPadView1 = [[FPNumberPadView alloc] initWithFrame:CGRectMake(0, 0, 948, 340)];
    numberPadView1.FPNumberPaddelegate=self;
    numberPadView1.textField = _maxGramTextField;
    
    FPNumberPadView *numberPadView2 = [[FPNumberPadView alloc] initWithFrame:CGRectMake(0, 0, 948, 340)];
    numberPadView2.FPNumberPaddelegate=self;
    numberPadView2.textField = _minAmountTextField;
    
    FPNumberPadView *numberPadView3 = [[FPNumberPadView alloc] initWithFrame:CGRectMake(0, 0, 948, 340)];
    numberPadView3.FPNumberPaddelegate=self;
    numberPadView3.textField = _maxAmountTextField;

     upYunImageArray=[NSMutableArray array];
  //  selectePictureArray=[NSMutableArray array];
    _remarkTextView.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1] CGColor];
    _remarkTextView.layer.borderWidth= 1.0f;
    _remarkTextView.layer.cornerRadius=3;
    CGRect viewFrame1=_remarkViewContainer.frame;
    viewFrame1.origin.y=_pictureView.frame.origin.y+_pictureView.frame.size.height+25;
    _remarkViewContainer.frame=viewFrame1;
    
    CGRect viewFrame2=_saveBtn.frame;
    viewFrame2.origin.y=_remarkViewContainer.frame.origin.y+_remarkViewContainer.frame.size.height+20;
    _saveBtn.frame=viewFrame2;
    
    [_addManagerRightScrollView setContentSize:CGSizeMake(0, _saveBtn.frame.origin.y+ _saveBtn.frame.size.height+10)];
    [_addManagerRightScrollView setScrollEnabled:YES];

    isOpened=NO;
    guideCodeStr=@"";
    styleCodeStr=@"";
    guideCodeArray=[NSMutableArray array];
    guideNameArray=[NSMutableArray array];
    
    styleCodeArray=[NSMutableArray array];
    styleNameArray=[NSMutableArray array];
    
    demandCodeArray=[NSMutableArray array];
   demandNameArray=[NSMutableArray array];
    selectDemandCodeArray=[NSMutableArray array];
    [_addManagerAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
     [_addManagerAlphaView addTarget:self action:@selector(addManagerAlphaViewClick) forControlEvents:UIControlEventTouchUpInside];
     [_selectGuideBtn addTarget:self action:@selector(selectGuideBtnClick) forControlEvents:UIControlEventTouchUpInside];
    CGRect viewFrame=_addManagerViewContainer.frame;
    viewFrame.origin.y=768;
    _addManagerViewContainer.frame=viewFrame;
    
    CGRect viewFrame3=_dateViewContainer.frame;
    viewFrame3.origin.y=768;
    _dateViewContainer.frame=viewFrame3;
    
    CGRect viewFrame4=_photoPickerViewContainer.frame;
    viewFrame4.origin.y=768;
    _photoPickerViewContainer.frame=viewFrame4;
    
    _guideListViewContainer.hidden=YES;
    CGRect frame=_guideListViewContainer.frame;
    frame.size.height=1;
    [_guideListViewContainer setFrame:frame];
    
    _styleListView.hidden=YES;
    _styleListViewContainer.hidden=YES;
    CGRect frame1=_styleListViewContainer.frame;
    frame1.size.height=1;
    [_styleListViewContainer setFrame:frame1];
}
-(void)selectGuideBtnClick
{
    if (isOpened) {
        _guideListViewContainer.hidden=YES;
        [UIView animateWithDuration:0.5 animations:^{
            
            UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
            [_selectGuideArrowImageView setImage:closeImage];
            CGRect frame=_guideListViewContainer.frame;
            
            frame.size.height=1;
            [_guideListViewContainer setFrame:frame];
            
        } completion:^(BOOL finished){
            isOpened=NO;
        }];
        
    }
    else
    {
        [self requestGuideList];
        _guideListViewContainer.hidden=NO;
        [UIView animateWithDuration:0.5 animations:^{
            UIImage *closeImage=[UIImage imageNamed:@"jiantou_upward.png"];
            
            
            [_selectGuideArrowImageView setImage:closeImage];
            CGRect frame=_guideListViewContainer.frame;
            
            frame.size.height=657;
            [_guideListViewContainer setFrame:frame];
            
        } completion:^(BOOL finished){
            isOpened=YES;
        }];
        
    }
    
}
-(void)requestTags
{
    // NSLog(@"##");
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [HttpRequest requestData:@"StoreManager/DemandRqList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    [demandCodeArray removeAllObjects];
                    [demandNameArray removeAllObjects];
                  NSMutableArray *mFeaturesArray=[severDataDict.dataDict objectForKey:@"DataLine"];
                    for (int i=0; i<mFeaturesArray.count; i++) {
                        [demandCodeArray addObject:[[mFeaturesArray objectAtIndex:i] objectForKey:@"DemandCode"]];
                        [demandNameArray addObject:[[mFeaturesArray objectAtIndex:i] objectForKey:@"DemandName"]];
                    }
                    //   NSLog(@"featureNameArray=%@",featureNameArray);
                    [self setTagView];
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                       [Global loginViewController:self noteStr:requestResultStr];
                      //  [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
}
-(void)setTagView
{
    for (int i=0; i<demandCodeArray.count; i++) {
        
        UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
        CGRect rect=button.frame;
        rect.size.height=32;
        rect.size.width=80;
        rect.origin.x=17+90*(i%6);
        rect.origin.y=13+46*(i/6);
        button.frame=rect;
        button.tag=i;
        [button setBackgroundColor:[UIColor clearColor]];
        button.layer.borderWidth=1;
        button.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1.0f] CGColor];
        button.layer.cornerRadius=16;
        button.titleLabel.font = [UIFont systemFontOfSize: 15.0];
        [button setTitle:[demandNameArray objectAtIndex:i] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor colorWithRed:100.0f/255.0f green:100.0f/255.0f blue:100.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];

//        [button setBackgroundColor:[UIColor colorWithRed:245.0f/255.0f green:245.0f/255.0f blue:245.0f/255.0f alpha:1.0f]];
//        [button setTitle:[demandNameArray objectAtIndex:i] forState:UIControlStateNormal];
//        [button setTitleColor:[UIColor colorWithRed:80.0f/255.0f green:80.0f/255.0f blue:80.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
//        if (memberDetailFeaturesNameArray.count>0) {
//            for (int j=0; j<memberDetailFeaturesNameArray.count; j++) {
//                if ([[featureNameArray objectAtIndex:i] isEqualToString:[memberDetailFeaturesNameArray objectAtIndex:j]]) {
//                    button.layer.borderColor=[[UIColor colorWithRed:252.0f/255.0f green:165.0f/255.0f blue:0.0f/255.0f alpha:1] CGColor];
//                    button.layer.borderWidth= 1.0f;
//                }
//            }
//        }
        [button addTarget:self action:@selector(tagButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [_managerTagView addSubview:button];
        CGRect frame1=_managerTagView.frame;
        frame1.size.height=46*((demandCodeArray.count/6)+1)+26;
        _managerTagView.frame=frame1;
        
        CGRect frame2=_pictureNoteView.frame;
        frame2.origin.y=_managerTagView.frame.size.height+_managerTagView.frame.origin.y;
        _pictureNoteView.frame=frame2;
        
        CGRect frame3=_pictureView.frame;
        frame3.origin.y=_pictureNoteView.frame.size.height+_pictureNoteView.frame.origin.y+2;
        _pictureView.frame=frame3;

    }
}
-(void)tagButtonClick:(UIButton *)sender
{
    [sender setBackgroundColor:[UIColor colorWithRed:254.0f/255.0f green:249.0f/255.0f blue:228.0f/255.0f alpha:1.0f]];
    sender.layer.borderWidth=1;
    sender.layer.borderColor=[[UIColor colorWithRed:226.0f/255.0f green:208.0f/255.0f blue:166.0f/255.0f alpha:1.0f] CGColor];
    [sender setTitleColor:[UIColor colorWithRed:209.0f/255.0f green:174.0f/255.0f blue:80.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
    
    if (![selectDemandCodeArray containsObject:[demandCodeArray objectAtIndex:sender.tag]]) {
        [selectDemandCodeArray addObject:[demandCodeArray objectAtIndex:sender.tag]];
        sender.layer.borderColor=[[UIColor colorWithRed:226.0f/255.0f green:208.0f/255.0f blue:166.0f/255.0f alpha:1.0f] CGColor];
        sender.layer.borderWidth= 1.0f;
        [sender setTitleColor:[UIColor colorWithRed:209.0f/255.0f green:174.0f/255.0f blue:80.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];

    }
    else
    {
        [selectDemandCodeArray removeObject:[demandCodeArray objectAtIndex:sender.tag]];
        sender.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1.0f] CGColor];
        sender.layer.borderWidth= 1.0f;
        [sender setBackgroundColor:[UIColor clearColor]];
        [sender setTitleColor:[UIColor colorWithRed:100.0f/255.0f green:100.0f/255.0f blue:100.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
    }
    // NSLog(@"selectCodeArray====%@",selectCodeArray);
}

-(void)requestGuideList
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [HttpRequest requestData:@"Guide/GuideList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    [guideCodeArray removeAllObjects];
                    [guideNameArray removeAllObjects];
                  NSMutableArray *mGuidesArray=[severDataDict.dataDict objectForKey:@"DataLine"];
                    for (int i=0; i<mGuidesArray.count; i++) {
                        [guideCodeArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"UserCode"]];
                        [guideNameArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"UserName"]];
                    }
                    // NSLog(@"guideCodeArray==%@",guideCodeArray);
                    //
                    [_guideListTableView reloadData];
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        [Global loginViewController:self noteStr:requestResultStr];
                      //  [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}

-(void)addManagerAlphaViewClick
{
    [HttpRequest cancelRequest];
    [_searchProductTextField resignFirstResponder];
    [_minGramTextField resignFirstResponder];
    [_maxGramTextField resignFirstResponder];
    [_minAmountTextField resignFirstResponder];
    [_maxAmountTextField resignFirstResponder];
    [_remarkTextView resignFirstResponder];

     isLoad=NO;
     [_addManagerRightScrollView setContentOffset:CGPointMake(0, 0)];
    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect viewFrame=_addManagerViewContainer.frame;
         viewFrame.origin.y=768;
         _addManagerViewContainer.frame=viewFrame;
     }completion:^(BOOL finished) {
         
     }];

}
-(void) loadProductNextPage:(NSUInteger)oldPageNum {
    if(oldPageNum!=0 && _productTotalCount<=managerNumArray.count)
        return;
    if(oldPageNum == 0){
        [managerNumArray removeAllObjects];
        [_managerTableView reloadData];
    }
    _productPageIndex=oldPageNum+1;
    [self requestManagerList: _productPageIndex pageSize:6];
}
-(void)requestManagerList:(NSUInteger)pageIndex pageSize:(NSUInteger)pageSize
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        NSNumber *pageSizeNumber = [NSNumber numberWithInteger:pageSize];
        NSNumber *pageIndexNumber = [NSNumber numberWithInteger:pageIndex];
        //        NSString *pageSizeStr=[NSString stringWithFormat:@"%d",pageSize];
        //        NSString *pageIndexStr=[NSString stringWithFormat:@"%d",pageIndex];
        
        [params setObject:pageSizeNumber forKey:@"PageSize"];
        [params setObject:pageIndexNumber forKey:@"PageIndex"];
        [params setObject:_searchProductTextField.text forKey:@"KeyWord"];
        NSMutableArray *mDocumentLine=[NSMutableArray array];
        for (int i=0; i<filterTypeCodeArray.count; i++) {
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            //    NSLog(@"codeContentssss==%@",codeContent);
            [dic setValue:[filterTypeCodeArray objectAtIndex:i] forKey:@"FilterTypeCode"];
            //  NSLog(@"countContentssss==%@",countContent);
            [dic setValue:[selectFilterCodeArray objectAtIndex:i] forKey:@"FilterCode"];
            [mDocumentLine addObject:dic];
            
        }
        NSMutableArray *mDocumentLine1=[NSMutableArray array];
        for (int i=0; i<customTimeFilterTypeCodeArray.count; i++) {
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            //    NSLog(@"codeContentssss==%@",codeContent);
            [dic setValue:[customTimeFilterTypeCodeArray objectAtIndex:i] forKey:@"FilterTypeCode"];
            //  NSLog(@"countContentssss==%@",countContent);
            [dic setValue:startTimeStr forKey:@"Value1"];
            [dic setValue:endTimeStr forKey:@"Value2"];
            [mDocumentLine1 addObject:dic];
            
        }

        [params setObject:mDocumentLine forKey:@"DataLineFileterParam"];
        [params setObject:mDocumentLine1 forKey:@"DataLineFileterParam2"];
        // NSLog(@"paramsLIST====%@",params);
        [HttpRequest requestData:@"StoreManager/DemandList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                
                    _productTotalCount=[[severDataDict.dataDict objectForKey:@"TotalCount"] integerValue];
                    _managerTotalCount.text=[NSString stringWithFormat:@"有%lu条记录",(unsigned long)_productTotalCount];
                    
                    if (_productTotalCount%6!=0) {
                        _productTotalPage=_productTotalCount/6+1;
                    }
                    else if (_productTotalCount%6==0)
                    {
                        _productTotalPage=_productTotalCount/6;
                    }
                   
                    NSMutableArray  *managerListArray=[severDataDict.dataDict objectForKey:@"DataLine"];
                    //   int total=0;
                    if ( managerListArray.count>0) {
                        for (int i=0; i< managerListArray.count; i++) {
                            [managerNumArray addObject:[[managerListArray objectAtIndex:i] objectForKey:@"DocNum"]];
                            [managerStatusArray addObject:[[managerListArray objectAtIndex:i] objectForKey:@"DocStatus"]];
                          //  [managerNumberArray addObject:[[managerListArray objectAtIndex:i] objectForKey:@"DocStatus"]];
                            [managerMinGramArray addObject:[[managerListArray objectAtIndex:i] objectForKey:@"MinGram"]];
                            [managerMaxGramArray addObject:[[managerListArray objectAtIndex:i] objectForKey:@"MaxGram"]];
                            [managerMinAmountArray addObject:[[managerListArray objectAtIndex:i] objectForKey:@"MinAmount"]];
                            [managerMaxAmountArray addObject:[[managerListArray objectAtIndex:i] objectForKey:@"MaxAmount"]];
                            [managerGuideNameArray addObject:[[managerListArray objectAtIndex:i] objectForKey:@"GuideName"]];
                            [managerProductNameArray addObject:[[managerListArray objectAtIndex:i] objectForKey:@"DocType"]];
                           // [managerGuideNameArray addObject:[[managerListArray objectAtIndex:i] objectForKey:@"UserName"]];
                            [managerDateArray addObject:[[managerListArray objectAtIndex:i] objectForKey:@"DocDate"]];

                        }
                    }
                    
                    [_managerTableView reloadData];
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        [Global loginViewController:self noteStr:requestResultStr];
                       // [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    if (_refreshHeaderView == nil) {
        
        EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - _managerTableView.bounds.size.height, self.view.frame.size.width, _managerTableView.bounds.size.height)];
        view.delegate = self;
        [_managerTableView addSubview:view];
        _refreshHeaderView = view;
        
        
    }
    
    //  update the last update date
    [_refreshHeaderView refreshLastUpdatedDate];

        // Do any additional setup after loading the view from its nib.
}
#pragma mark -
#pragma mark Data Source Loading / Reloading Methods

- (void)reloadTableViewDataSource{
    [managerNumArray removeAllObjects];
    [managerStatusArray removeAllObjects];
    [managerMinGramArray removeAllObjects];
    [managerMaxGramArray removeAllObjects];
    [managerMinAmountArray removeAllObjects];
    [managerMaxAmountArray removeAllObjects];
    [managerGuideNameArray removeAllObjects];
    [managerProductNameArray removeAllObjects];
    // [managerGuideNameArray addObject:[[managerListArray objectAtIndex:i] objectForKey:@"UserName"]];
    [managerDateArray removeAllObjects];

    _productPageIndex=0;
    [self loadProductNextPage:_productPageIndex];
    //  should be calling your tableviews data source model to reload
    //  put here just for demo
    _reloading = YES;
    
}

- (void)doneLoadingTableViewData{
    
    //  model should call this when its done loading
    _reloading = NO;
    [_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:_managerTableView];
    
}


#pragma mark -
#pragma mark UIScrollViewDelegate Methods

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
     if (scrollView==_managerTableView) {
    [_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
     }
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
     if (scrollView==_managerTableView) {
    [_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
     }
    
}


#pragma mark -
#pragma mark EGORefreshTableHeaderDelegate Methods

- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{
    
    [self reloadTableViewDataSource];
    [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0];
    
}

- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{
    
    return _reloading; // should return if data source model is reloading
    
}

- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{
    
    return [NSDate date]; // should return date data source was last changed
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    //    NSMutableArray *codeArrays = [NSMutableArray arrayWithArray:[shopCartData objectForKey:@"PRODUCTCODE"]];
    //    return [codeArrays count];
    if (tableView ==_managerTableView) {
        return managerNumArray.count;
    }
    else if(tableView==_guideListTableView)
    {
        return guideCodeArray.count;
    }
    else if(tableView==_styleListTableView)
    {
        return styleCodeArray.count;
    }


    return 1;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(tableView==_managerTableView)
        return 120.0f;
    return 55;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView==_managerTableView) {
        static NSString * ManagerGoodidentifier = @"ManagerGoodCell";
        ManagerGoodTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:ManagerGoodidentifier];
        
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"ManagerGoodTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
            // cell.delegate=self;
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (managerNumArray.count>0) {
            cell.numLabel.text=[managerNumArray objectAtIndex:indexPath.row];
            // NSLog(@"cell.numLabel.text=%@",cell.numLabel.text);
          //  [self resizeLabel:cell.numLabel];
          
            
           cell.numLabel.numberOfLines = 0;
            cell.numLabel.lineBreakMode = NSLineBreakByWordWrapping;
            CGSize maximumLabelSize = CGSizeMake(1000, cell.numLabel.frame.size.height);
            
            CGSize expectSize = [cell.numLabel sizeThatFits:maximumLabelSize];
            CGRect frame1 = CGRectMake(cell.numLabel.frame.origin.x, cell.numLabel.frame.origin.y,expectSize.width, cell.numLabel.frame.size.height );
            cell.numLabel.frame=frame1;
            
            CGRect frame=cell.statusLabel.frame;
            frame.origin.x=cell.numLabel.frame.origin.x+cell.numLabel.frame.size.width;
            cell.statusLabel.frame=frame;
        }

        if (managerStatusArray.count>0) {
            NSString *statusStr=[managerStatusArray objectAtIndex:indexPath.row];
            cell.statusLabel.text=[NSString stringWithFormat:@"【%@】",statusStr];
            if ([statusStr isEqualToString:@"已下达"]) {
                [cell.statusLabel setTextColor:[Global parseStatusColor:statusStr]];
            }
            else
            {
                [cell.statusLabel setTextColor:[Global parseStatusColor:statusStr]];
            }
            
        }

        NSString *minAmountStr=@"";
        NSString *maxAmountStr=@"";
        NSString *minGramStr=@"";
        NSString *maxGramStr=@"";
        NSString *nameStr=@"";
        
        if (managerMinAmountArray.count>0) {
            float AvgPrice=[[managerMinAmountArray objectAtIndex:indexPath.row] floatValue];
            NSString *AvgPriceStr=[Global floatConvertPercentile:AvgPrice];
            //  NSString *marketStr=[NSString stringWithFormat:@"¥%0.02f",[[inquiryPriceArray objectAtIndex:indexPath.row] floatValue]];
        //    cell.priceLabel.text=[NSString stringWithFormat:@"¥%@",AvgPriceStr];
           minAmountStr =[NSString stringWithFormat:@"¥%@",AvgPriceStr];
        }
        if (managerMaxAmountArray.count>0) {
            float AvgPrice=[[managerMaxAmountArray objectAtIndex:indexPath.row] floatValue];
            NSString *AvgPriceStr=[Global floatConvertPercentile:AvgPrice];

            maxAmountStr=[NSString stringWithFormat:@"¥%@",AvgPriceStr];
        }
        if (managerMinGramArray.count>0) {
            float AvgPrice=[[managerMinGramArray objectAtIndex:indexPath.row] floatValue];
            NSString *AvgPriceStr=[Global floatConvertPercentile:AvgPrice];
            minGramStr =[NSString stringWithFormat:@"%@g",AvgPriceStr];
        }
        if (managerMaxGramArray.count>0) {
            float AvgPrice=[[managerMaxGramArray objectAtIndex:indexPath.row] floatValue];
            NSString *AvgPriceStr=[Global floatConvertPercentile:AvgPrice];
            
            maxGramStr=[NSString stringWithFormat:@"%@g",AvgPriceStr];
        }

        if (managerDateArray.count>0) {
            cell.dateLabel.text=[managerDateArray objectAtIndex:indexPath.row];
        }
        if (managerGuideNameArray.count>0) {
            NSString *guideNameStr=[managerGuideNameArray objectAtIndex:indexPath.row];
            if (guideNameStr.length>0) {
                cell.guideNameLabel.text=guideNameStr;
            }
            else
            {
                cell.guideNameLabel.text=@"未填写";
            }
            
            cell.guideNameLabel.numberOfLines = 0;
            cell.guideNameLabel.lineBreakMode = NSLineBreakByWordWrapping;
            CGSize maximumLabelSize = CGSizeMake(1000, cell.guideNameLabel.frame.size.height);
            
            CGSize expectSize = [cell.guideNameLabel sizeThatFits:maximumLabelSize];
            CGRect frame0 = CGRectMake(cell.guideNameLabel.frame.origin.x, cell.guideNameLabel.frame.origin.y,expectSize.width, cell.guideNameLabel.frame.size.height );
            cell.guideNameLabel.frame=frame0;

          //  [self resizeLabel:cell.guideNameLabel];
            CGRect frame=cell.dateTagLabel.frame;
            frame.origin.x=cell.guideNameLabel.frame.origin.x+cell.guideNameLabel.frame.size.width+15;
            cell.dateTagLabel.frame=frame;
            
            CGRect frame1=cell.dateLabel.frame;
            frame1.origin.x=cell.dateTagLabel.frame.origin.x+cell.dateTagLabel.frame.size.width+3;
            cell.dateLabel.frame=frame1;
            
            
        }
     //   NSLog(@"minGramStr==%@,maxGramStr==%@",minGramStr,maxGramStr);
        if (managerProductNameArray.count>0) {
            if([managerProductNameArray objectAtIndex:indexPath.row]!=[NSNull null])
            {
             nameStr=[managerProductNameArray objectAtIndex:indexPath.row];
            }
            cell.productNameLabel.text=[NSString stringWithFormat:@"%@/%@~%@",nameStr,minGramStr,maxGramStr];
            
            cell.productNameLabel.numberOfLines = 0;
            cell.productNameLabel.lineBreakMode = NSLineBreakByWordWrapping;
            CGSize maximumLabelSize = CGSizeMake(1000, cell.numLabel.frame.size.height);
            
            CGSize expectSize = [cell.productNameLabel sizeThatFits:maximumLabelSize];
            CGRect frame0 = CGRectMake(cell.productNameLabel.frame.origin.x, cell.productNameLabel.frame.origin.y,expectSize.width, cell.productNameLabel.frame.size.height );
            cell.productNameLabel.frame=frame0;
            
            CGRect frame=cell.priceTagLabel.frame;
            frame.origin.x=cell.productNameLabel.frame.origin.x+cell.productNameLabel.frame.size.width+15;
            cell.priceTagLabel.frame=frame;
            
            CGRect frame1=cell.priceLabel.frame;
            frame1.origin.x=cell.priceTagLabel.frame.origin.x+cell.priceTagLabel.frame.size.width+3;
            cell.priceLabel.frame=frame1;
            cell.priceLabel.text=[NSString stringWithFormat:@"%@~%@",minAmountStr,maxAmountStr];
            
        }
        
        
        if (indexPath.row == [managerNumArray count] - 1)
        {
            if (_productPageIndex<=_productTotalPage) {
                //    NSLog(@"###LOADING???");
                [self loadProductNextPage:_productPageIndex];
            }
            
        }
        return cell;
    }
    else if(tableView==_guideListTableView)
    {
        static NSString * const  GuideListIdentifier = @"GuideListCellIdentifier";
        GuideListTableViewCell *cell=( GuideListTableViewCell *)[tableView dequeueReusableCellWithIdentifier: GuideListIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"GuideListTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (guideNameArray.count>0) {
            cell.guideNameLabel.text=[guideNameArray objectAtIndex:indexPath.row];
        }
        return cell;
        
    }
    else if(tableView==_styleListTableView)
    {
        static NSString * const  StyleListIdentifier = @"StyleListIdentifier";
        GuideListTableViewCell *cell=( GuideListTableViewCell *)[tableView dequeueReusableCellWithIdentifier: StyleListIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"GuideListTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (styleNameArray.count>0) {
            cell.guideNameLabel.text=[styleNameArray objectAtIndex:indexPath.row];
        }
        return cell;
        
    }

    return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==_guideListTableView) {
        guideCodeStr=[guideCodeArray objectAtIndex:indexPath.row];
        
        _guideListViewContainer.hidden=YES;
        [UIView animateWithDuration:0.5 animations:^{
            
            UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
            [_selectGuideArrowImageView setImage:closeImage];
            CGRect frame=_guideListViewContainer.frame;
            
            frame.size.height=1;
            [_guideListViewContainer setFrame:frame];
            
        } completion:^(BOOL finished){
            isOpened=NO;
        }];
        _guideNameLabel.text=[guideNameArray objectAtIndex:indexPath.row];
    }
   else if (tableView==_styleListTableView) {
        styleCodeStr=[styleCodeArray objectAtIndex:indexPath.row];
       
       _styleListView.hidden=YES;
        _styleListViewContainer.hidden=YES;
        [UIView animateWithDuration:0.5 animations:^{
            
           // UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
          //  [_selectGuideArrowImageView setImage:closeImage];
            CGRect frame=_styleListViewContainer.frame;
            
            frame.size.height=1;
            [_styleListViewContainer setFrame:frame];
            
        } completion:^(BOOL finished){
           // isOpened=NO;
        }];
        _styleTextField.text=[styleNameArray objectAtIndex:indexPath.row];
    }
else if (tableView==_managerTableView)
{
    [_searchProductTextField resignFirstResponder];
    for (UIView *v in _requireTagView.subviews) {
            
            [v removeFromSuperview];
        
    }
    for (UIView *v in _detailPictureView.subviews) {
        
        [v removeFromSuperview];
        
    }


    [self requestManagerDetail:[managerNumArray objectAtIndex: indexPath.row]];
    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect viewFrame=_managerDetailViewContainer.frame;
         viewFrame.origin.y=0;
         _managerDetailViewContainer.frame=viewFrame;
     }completion:^(BOOL finished) {
         
     }];

}
    //    for (UIView *v in _rightScrollView.subviews) {
    //        if (v.tag==9) {
    //
    //            [v removeFromSuperview];
    //        }
    //
    //    }
    //
    //    [self requestItemDetail:[inquiryItemCodeArray objectAtIndex:indexPath.row]];
    //    [UIView animateWithDuration:0.5 animations:^{
    //        CGRect frame=_productDetailViewContainer.frame;
    //
    //        frame.origin.y=0;
    //        [_productDetailViewContainer setFrame:frame];
    //
    //    } completion:^(BOOL finished){
    //
    //    }];
    
}
-(void)requestManagerDetail:(NSString *)numStr
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
         [params setObject:numStr forKey:@"DocNum"];
        [HttpRequest requestData:@"StoreManager/DemandDetail" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
           // NSLog(@"666666666=%@",severDataDict.dataDict);
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    _detailNumLabel.text=[severDataDict.dataDict objectForKey:@"DocNum"];
                    _detailGuideNameLabel.text=[severDataDict.dataDict objectForKey:@"GuideName"];
                    // [self resizeLabel:_detailGuideNameLabel];
                    [Global resizeForLable:_detailGuideNameLabel WithText:_detailGuideNameLabel.text parentView:self.view];
                    CGRect frame1=_detailStoreNameTagLabel.frame;
                    frame1.origin.x=_detailGuideNameLabel.frame.origin.x+_detailGuideNameLabel.frame.size.width+15;
                    _detailStoreNameTagLabel.frame=frame1;
//
                    CGRect frame2=_detailStoreNameLabel.frame;
                    frame2.origin.x=_detailStoreNameTagLabel.frame.origin.x+_detailStoreNameTagLabel.frame.size.width+3;
                    _detailStoreNameLabel.frame=frame2;
                    
                    _detailStoreNameLabel.text=[severDataDict.dataDict objectForKey:@"StoreName"];

                    _detailDateNameLabel.text=[severDataDict.dataDict objectForKey:@"DocDate"];
                    if ([severDataDict.dataDict objectForKey:@"DocType"]!=[NSNull null]) {
                        _detailStyleLabel.text=[severDataDict.dataDict objectForKey:@"DocType"];
                    }
                    
                  //  [self resizeLabel:_detailStyleLabel];
                     [Global resizeForLable:_detailStyleLabel WithText:_detailStyleLabel.text parentView:self.view];
//                     NSString *minGramStr=[NSString stringWithFormat:@"%0.02f",[[severDataDict.dataDict objectForKey:@"MinGram"] floatValue]];
                    NSString *minGramStr=[NSString stringWithFormat:@"%0.02f",[[severDataDict.dataDict objectForKey:@"MinGram"] floatValue]];
                    
                    
                    NSString *maxGramStr=[NSString stringWithFormat:@"%0.02f",[[severDataDict.dataDict objectForKey:@"MaxGram"] floatValue]];
                     NSString *minAmountStr=[NSString stringWithFormat:@"%0.02f",[[severDataDict.dataDict objectForKey:@"MinAmount"] floatValue]];
                    
                    float AvgPrice=[[severDataDict.dataDict objectForKey:@"MaxAmount"] floatValue];
                    NSString *maxAmountStr=[Global floatConvertPercentile:AvgPrice];
                  //  NSString *maxAmountStr=[NSString stringWithFormat:@"%0.02f",];
                    _detailWeightLabel.text=[NSString stringWithFormat:@"%@g~%@g",minGramStr,maxGramStr];
                   //  [self resizeLabel:_detailWeightLabel];
                    [Global resizeForLable:_detailWeightLabel WithText:_detailWeightLabel.text parentView:self.view];
                    _detailPriceLabel.text=[NSString stringWithFormat:@"¥%@~¥%@",minAmountStr,maxAmountStr];
                    
                    CGRect frame3=_detailWeightTagLabel.frame;
                    frame3.origin.x=_detailStyleLabel.frame.origin.x+_detailStyleLabel.frame.size.width+15;
                    _detailWeightTagLabel.frame=frame3;
                    
                    CGRect frame4=_detailWeightLabel.frame;
                    frame4.origin.x=_detailWeightTagLabel.frame.origin.x+_detailWeightTagLabel.frame.size.width+3;
                    _detailWeightLabel.frame=frame4;
                    
                    CGRect frame5=_detailPriceTagLabel.frame;
                    frame5.origin.x=_detailWeightLabel.frame.origin.x+_detailWeightLabel.frame.size.width+15;
                    _detailPriceTagLabel.frame=frame5;
                    
                    CGRect frame6=_detailPriceLabel.frame;
                    frame6.origin.x=_detailPriceTagLabel.frame.origin.x+_detailPriceTagLabel.frame.size.width+3;
                    _detailPriceLabel.frame=frame6;


                
                    _detailRemarkView.text=[severDataDict.dataDict objectForKey:@"Remark"];

                    NSMutableArray *mDetailTagArray=[severDataDict.dataDict objectForKey:@"DataLine"];
                    NSMutableArray *detailTagNameArray=[NSMutableArray array];
                    for (int i=0; i<mDetailTagArray.count; i++) {
                       
                        [detailTagNameArray addObject:[[mDetailTagArray objectAtIndex:i] objectForKey:@"DemandName"]];
                    }
                    [self setDetailTagView:detailTagNameArray];
                    
                    NSMutableArray *mDetailPictureArray=[severDataDict.dataDict objectForKey:@"DataLine1"];
                    NSMutableArray *detailImageUrlArray=[NSMutableArray array];
                    for (int i=0; i<mDetailPictureArray.count; i++) {
                        
                        [detailImageUrlArray addObject:[[mDetailPictureArray objectAtIndex:i] objectForKey:@"ImageUrl"]];
                    }

                    [self setDetailPicture:detailImageUrlArray];
                    // NSLog(@"guideCodeArray==%@",guideCodeArray);
                    //
                    [_styleListTableView reloadData];
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        [Global loginViewController:self noteStr:requestResultStr];
                       // [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }

}
-(void)setDetailTagView:(NSMutableArray *)tagArray
{
    for (int i=0; i<tagArray.count; i++) {
        
        UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
        button.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1] CGColor];
        button.layer.borderWidth= 1.0f;
        button.layer.cornerRadius=3;

        CGRect rect=button.frame;
        rect.size.height=32;
        rect.size.width=80;
        rect.origin.x=17+90*(i%6);
        rect.origin.y=17+46*(i/6);
        button.frame=rect;
        [button setBackgroundColor:[UIColor colorWithRed:254.0f/255.0f green:249.0f/255.0f blue:228.0f/255.0f alpha:1.0f]];
        button.layer.borderWidth=1;
        button.layer.borderColor=[[UIColor colorWithRed:226.0f/255.0f green:208.0f/255.0f blue:166.0f/255.0f alpha:1.0f] CGColor];
        button.layer.cornerRadius=16;
        button.titleLabel.font = [UIFont systemFontOfSize: 15.0];
        [button setTitleColor:[UIColor colorWithRed:209.0f/255.0f green:174.0f/255.0f blue:80.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
       // button.tag=i;
        //[button setBackgroundColor:[UIColor colorWithRed:245.0f/255.0f green:245.0f/255.0f blue:245.0f/255.0f alpha:1.0f]];
        [button setTitle:[tagArray objectAtIndex:i] forState:UIControlStateNormal];
        //[button setTitleColor:[UIColor colorWithRed:80.0f/255.0f green:80.0f/255.0f blue:80.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
        
        [_requireTagView addSubview:button];
    }

}
-(void)setDetailPicture:(NSMutableArray *)imageArray
{
  //  NSLog(@"sampleImageView====%@",imageArray);
    float viewHeight=0.0f;
    for (int i=0; i<imageArray.count; i++) {
        
        UIButton *imageButton=[UIButton buttonWithType:UIButtonTypeCustom];
      //
//        sampleImageView.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1] CGColor];
//        sampleImageView.layer.borderWidth= 1.0f;
//        sampleImageView.layer.cornerRadius=3;
        CGRect rect=imageButton.frame;
        imageButton.tag=i+1;
        rect.size.height=90;
        rect.size.width=90;
        rect.origin.x=25+(90+25)*(i%5);
        rect.origin.y=17+100*(i/5);
       // NSLog(@"i/6=====%d",i/5);
        imageButton.frame=rect;
        viewHeight=rect.origin.y+rect.size.height+15;
        [imageButton addTarget:self action:@selector(imageButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        UIImageView *sampleImageView=[[UIImageView alloc] initWithFrame:imageButton.frame];
        sampleImageView.tag=i+1+100;
        [sampleImageView setImageWithURL:[NSURL URLWithString:[imageArray objectAtIndex:i]]];
         [_detailPictureView addSubview:sampleImageView];
        [_detailPictureView addSubview:imageButton];
       // NSLog(@"rect.origin.x==%f",rect.origin.x);
        
    }
    //NSLog(@"viewHeight===%f",viewHeight);
    CGRect viewFrame=_detailPictureView.frame;
    viewFrame.size.height=viewHeight;
    _detailPictureView.frame=viewFrame;
    
    CGRect viewFrame1=_detailLastView.frame;
    viewFrame1.origin.y=_detailPictureView.frame.origin.y+_detailPictureView.frame.size.height;
    _detailLastView.frame=viewFrame1;
    
}
-(void)imageButtonClick:(UIButton *)sender
{
   // NSLog(<#NSString *format, ...#>)
    UIImageView *imageview=(UIImageView *)[_detailPictureView viewWithTag:sender.tag+100];
   
    
  //  _imageViewContainer.frame=sender.frame;
    _detailLargeImageView.image=imageview.image;
    _imageViewContainer.hidden=NO;
    
//    [UIView beginAnimations:nil context:nil];
//    // 动画时间
//    [UIView setAnimationDuration:1];
//    
//        // 放大尺寸
//        _imageViewContainer.frame = CGRectMake(0, 0,948,768);
//    
//    
//    [UIView commitAnimations];
    
}
-(IBAction)detailLargeImageButtonClick:(id)sender
{
    _imageViewContainer.hidden=YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField==_searchProductTextField) {
        [managerNumArray removeAllObjects];
        [managerStatusArray removeAllObjects];
        [managerMinGramArray removeAllObjects];
        [managerMaxGramArray removeAllObjects];
        [managerMinAmountArray removeAllObjects];
        [managerMaxAmountArray removeAllObjects];
        [managerGuideNameArray removeAllObjects];
        [managerProductNameArray removeAllObjects];
        // [managerGuideNameArray addObject:[[managerListArray objectAtIndex:i] objectForKey:@"UserName"]];
        [managerDateArray removeAllObjects];

        _productPageIndex=0;
        [self loadProductNextPage:_productPageIndex];
        [_searchProductTextField resignFirstResponder];
    }

    return YES;
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
      if (textField==_dateTextField)
      {
       
        [_minAmountTextField resignFirstResponder];
        [_minGramTextField resignFirstResponder];
        [_maxAmountTextField resignFirstResponder];
        [_maxGramTextField resignFirstResponder];
        [UIView animateWithDuration:0.5f animations:^
         {
             CGRect viewFrame=_dateViewContainer.frame;
             viewFrame.origin.y=65;
             _dateViewContainer.frame=viewFrame;
         }completion:^(BOOL finished) {
             
             
         }];
       //  NSLog(@"_dateViewContainer.frame.y==%f",_dateViewContainer.frame.origin.y);
        return NO;
        
    }
    if (textField==_styleTextField)
    {
        [self requestStyleList];
        [_minAmountTextField resignFirstResponder];
        [_minGramTextField resignFirstResponder];
        [_maxAmountTextField resignFirstResponder];
        [_maxGramTextField resignFirstResponder];
        _styleListView.hidden=NO;
        _styleListViewContainer.hidden=NO;
        [UIView animateWithDuration:0.5 animations:^{
           // UIImage *closeImage=[UIImage imageNamed:@"jiantou_upward.png"];
            
            
            //[_selectGuideArrowImageView setImage:closeImage];
            CGRect frame=_styleListViewContainer.frame;
            
            frame.size.height=551;
            [_styleListViewContainer setFrame:frame];
            
        } completion:^(BOOL finished){
            isOpened=YES;
        }];
        
       // NSLog(@"_dateViewContainer.frame.y==%f",_dateViewContainer.frame.origin.y);
        return NO;
        
    }

    
    return YES;

}
-(void)requestStyleList
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [HttpRequest requestData:@"StoreManager/DemTypeList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    [styleCodeArray removeAllObjects];
                    [styleNameArray removeAllObjects];
                  //  NSLog(@"3333=%@",severDataDict.dataDict);
                    NSMutableArray *mGuidesArray=[severDataDict.dataDict objectForKey:@"DataLine"];
                    for (int i=0; i<mGuidesArray.count; i++) {
                        [styleCodeArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"DemTypeCode"]];
                        [styleNameArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"DemTypeName"]];
                    }
                    // NSLog(@"guideCodeArray==%@",guideCodeArray);
                    //
                    [_styleListTableView reloadData];
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        [Global loginViewController:self noteStr:requestResultStr];
                       // [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}

-(IBAction)oneDatePickerValueChanged:(UIDatePicker *)sender
{
    NSDate *selectedDate =[sender date];
    //NSLog(@"curDate is %@" ,selectedDate);
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];//修改时区为东8区
    
    NSString *destDateString = [dateFormatter stringFromDate:selectedDate];
    _dateTextField.text=destDateString;
    // NSLog(@"destDateString is %@" ,destDateString);
}

-(IBAction)birthViewConfirmClick:(id)sender
{
    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect viewFrame=_dateViewContainer.frame;
         viewFrame.origin.y=768;
         _dateViewContainer.frame=viewFrame;
     }completion:^(BOOL finished) {
         
         
     }];
    
    NSDate *selectedDate =[_datePickerView date];
    //NSLog(@"curDate is %@" ,selectedDate);
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];//修改时区为东8区
    
    NSString *destDateString = [dateFormatter stringFromDate:selectedDate];
    _dateTextField.text=destDateString;
    
    
}
-(IBAction)addPictureBtnClick:(id)sender
{
    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect viewFrame=_photoPickerViewContainer.frame;
         viewFrame.origin.y=0;
         _photoPickerViewContainer.frame=viewFrame;
     }completion:^(BOOL finished) {
         
         
     }];

}
-(IBAction)saveManagerBtnClick:(id)sender
{
     isLoad=NO;
    [upYunImageArray removeAllObjects];
    if (_pictureView.subviews.count>2) {
        if ([Global getLoginToken].length>0) {
            [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
            NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
            [params setObject:[Global getLoginToken] forKey:@"Token"];
            [params setObject:@"DDemand" forKey:@"uploadType"];
         //   NSLog(@"params====%@",params);
            [HttpRequest requestLoginData:@"System/GetFormParams" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
              //  NSLog(@"serrr111==%@",severDataDict.dataDict);
                // [_cashierSearchMemberTextField resignFirstResponder];
                if (isSuccess) {
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                        [Global hideProgressHUDInternal:self.view];
                        [Global setUpYunUrl:[severDataDict.dataDict objectForKey:@"action"]];
                       // signatureStr=[severDataDict.dataDict objectForKey:@"signature"];
                       // policyStr=[severDataDict.dataDict objectForKey:@"policy"];
                        
                        [Global setSignatureStr:[severDataDict.dataDict objectForKey:@"signature"]];
                        [Global setPolicyStr:[severDataDict.dataDict objectForKey:@"policy"]];
                        
                        [self upToUpYun];
                    }
                    else
                    {
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        //  [Global showTextHud:requestResultStr view:self.view];
                        [Global showTextHudSub:requestResultStr view:self.view];
                        
                        if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                           [Global loginViewController:self noteStr:requestResultStr];
                         //   [Global loginViewController:self];
                        }

                    }
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    [Global showTextHudSub:@"连接失败" view:self.view];
                }
            }];
        }
        

//    [self upToUpYun];
    }
    else
    {
         // NSLog(@"14444477777");
         [self saveManagerToServer];
    }
}
-(void)upToUpYun
{
     __block NSInteger count=0;
    UpYun *uy = [[UpYun alloc] init];
    uy.successBlocker = ^(id data)
    {
        count++;
       // NSLog(@"count======%d",count );
       // NSLog(@"_pictureView.subviews.count======%d",_pictureView.subviews.count );
        
        NSString *imageURL;
        NSString *imageWIDTH;
        NSString *imageHEIGHT;
        imageURL=[data objectForKey:@"url"];
        imageWIDTH=[data objectForKey:@"image-width"];
        imageHEIGHT=[data objectForKey:@"image-height"];
        NSMutableDictionary *upYunImageDict=[NSMutableDictionary dictionary];
        [upYunImageDict setObject:imageURL forKey:@"ImageUrl"];
        [upYunImageDict setObject:imageWIDTH forKey:@"ImageWidth"];
        [upYunImageDict setObject:imageHEIGHT forKey:@"ImageHeigh"];
        [upYunImageArray addObject:upYunImageDict];
        if (count==_pictureView.subviews.count-2-(_pictureView.subviews.count-2)/2) {
          
            [Global hideProgressHUDInternal:self.view];
            [self saveManagerToServer];
        }

        
    };
    uy.failBlocker = ^(NSError * error)
    {
         [Global hideProgressHUDInternal:self.view];
        NSString *message = [error.userInfo objectForKey:@"message"];
        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"error" message:message delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alert show];
      //  NSLog(@"%@",error);
    };
    uy.progressBlocker = ^(CGFloat percent, long long requestDidSendBytes)
    {
       // [_pv setProgress:0.3333333333+percent/3];
    };
    
    if (guideCodeStr.length>0&&_dateTextField.text.length>0&&styleCodeStr.length>0&&((_maxGramTextField.text.length>0&&[_maxGramTextField.text floatValue]>=[_minGramTextField.text floatValue])||(_maxAmountTextField.text.length>0&&[_maxAmountTextField.text floatValue]>=[_minAmountTextField.text floatValue]))) {

     [Global showIndeterminateHudSub:@"正上传UPYUN，请稍后。。。" delay:120 view:self.view];
        if (upYunImageArray.count==0) {
      
    for (UIView *v in _pictureView.subviews) {
        if (v.tag!=90&&v.tag>50) {
            UIImageView *imageview=(UIImageView *)v;
             UIImage *sampleImg=[self imageCompress:imageview.image];
         
//            NSData *imageData = UIImageJPEGRepresentation(imageview.image,0.01);
//            //NSLog(@"imageData===%@",imageData);
//            UIImage *newImage = [UIImage imageWithData:imageData];

            uy.bucket=@"";
             [uy uploadFile:sampleImg saveKey:[self getSaveKey]];
        }
        
         }
        }

    
    }
    else
    {
        // NSLog(<#NSString *format, ...#>)
        if (guideCodeStr.length==0) {
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选择导购" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
        }
        else if(_dateTextField.text.length==0)
        {
            //if (guideCodeStr.length==0) {
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选择日期" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
            // }
            
        }
        else if(styleCodeStr.length==0)
        {
            //if (guideCodeStr.length==0) {
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选择类型" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
            // }
            
        }
        
        else if (_minGramTextField.text.length==0&&_maxGramTextField.text.length==0&&_minAmountTextField.text.length==0&&_maxAmountTextField.text.length==0)
        {
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选填克重或金额" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
            
        }
        else if ([_maxGramTextField.text floatValue]<[_minGramTextField.text floatValue])
        {
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"最大克重需大于最小克重，请重新输入" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
            
        }
        
        
        else if ([_maxAmountTextField.text floatValue]<[_minAmountTextField.text floatValue])
        {
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"最大金额需大于最小金额，请重新输入" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
            
        }
        
    }
    
}
-(void)saveManagerToServer
{
    isLoad=NO;
    if (guideCodeStr.length>0&&_dateTextField.text.length>0&&styleCodeStr.length>0&&((_maxGramTextField.text.length>0&&[_maxGramTextField.text floatValue]>=[_minGramTextField.text floatValue])||(_maxAmountTextField.text.length>0&&[_maxAmountTextField.text floatValue]>=[_minAmountTextField.text floatValue]))) {
        
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableArray *codeDataLine=[NSMutableArray array];
        for (int i=0; i<selectDemandCodeArray.count; i++) {
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            NSString *codeStr = [selectDemandCodeArray objectAtIndex:i];
            [dic setValue:codeStr forKey:@"DemandCode"];
            
            [codeDataLine addObject:dic];
        }
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:codeDataLine forKey:@"DataLine"];
         [params setObject:upYunImageArray forKey:@"DataLine1"];
        [params setObject:_remarkTextView.text forKey:@"Remark"];
        [params setObject:_dateTextField.text forKey:@"DocDate"];
        [params setObject:styleCodeStr forKey:@"DocType"];
        [params setObject:guideCodeStr forKey:@"GuideCode"];
        [params setObject:_minGramTextField.text forKey:@"MinGram"];
        [params setObject:_maxGramTextField.text forKey:@"MaxGram"];
        [params setObject:_minAmountTextField.text forKey:@"MinAmount"];
        [params setObject:_maxAmountTextField.text forKey:@"MaxAmount"];
       //   NSLog(@"addddPARAM1111===%@",params);
        [HttpRequest requestData:@"StoreManager/AddDemand" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    [managerNumArray removeAllObjects];
                    [managerStatusArray removeAllObjects];
                    [managerMinGramArray removeAllObjects];
                    [managerMaxGramArray removeAllObjects];
                    [managerMinAmountArray removeAllObjects];
                    [managerMaxAmountArray removeAllObjects];
                    [managerGuideNameArray removeAllObjects];
                    [managerProductNameArray removeAllObjects];
                    // [managerGuideNameArray addObject:[[managerListArray objectAtIndex:i] objectForKey:@"UserName"]];
                    [managerDateArray removeAllObjects];

                    _productPageIndex=0;
                    [self loadProductNextPage:_productPageIndex];
                    _dateTextField.text=@"";
                    _styleTextField.text=@"";
                    _minGramTextField.text=@"";
                    _maxGramTextField.text=@"";
                    _minAmountTextField.text=@"";
                    _maxAmountTextField.text=@"";
                    _guideNameLabel.text=@"";
                    guideCodeStr=@"";
                    [UIView animateWithDuration:0.3 animations:^{
                        CGRect viewFrame=_addManagerViewContainer.frame;
                        viewFrame.origin.y=768;
                        _addManagerViewContainer.frame=viewFrame;
                    } completion:^(BOOL finished){
                        
                    }];
                     [_addManagerRightScrollView setContentOffset:CGPointMake(0, 0)];
                    CGRect viewFrame=_pictureView.frame;
                    viewFrame.size.height=118;
                    _pictureView.frame=viewFrame;
                    
                    CGRect viewFrame0=_pictureViewLineLabel.frame;
                    viewFrame0.origin.y= _pictureView.frame.size.height-1;
                    _pictureViewLineLabel.frame=viewFrame0;
                    CGRect viewFrame1=_remarkViewContainer.frame;
                    viewFrame1.origin.y=_pictureView.frame.origin.y+_pictureView.frame.size.height+15;
                    _remarkViewContainer.frame=viewFrame1;
                    
                    CGRect viewFrame2=_saveBtn.frame;
                    viewFrame2.origin.y=_remarkViewContainer.frame.origin.y+_remarkViewContainer.frame.size.height+20;
                    _saveBtn.frame=viewFrame2;
                    
                    _textViewImageView.hidden=NO;
                    _textViewLabel.hidden=NO;
                    _remarkTextView.text=@"";
                    for (UIButton *button in _managerTagView.subviews) {
                        // [button removeFromSuperview];
                        button.layer.borderColor=[[UIColor colorWithRed:252.0f/255.0f green:165.0f/255.0f blue:0.0f/255.0f alpha:1] CGColor];
                        button.layer.borderWidth= 0.0f;
                    }
                    for (UIView *v in _pictureView.subviews) {
                        if (v.tag!=90) {
                            
                            [v removeFromSuperview];
                        }
                        
                    }
                    [selectDemandCodeArray removeAllObjects];
                    
                    CGRect viewFrame11=_addPictureButton.frame;
                    viewFrame11.origin.y=10;
                     viewFrame11.origin.x=16;
                    _addPictureButton.frame=viewFrame11;

                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                      [Global loginViewController:self noteStr:requestResultStr];   
                    //    [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    }
    else
    {
       // NSLog(<#NSString *format, ...#>)
        if (guideCodeStr.length==0) {
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选择导购" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
        }
        else if(_dateTextField.text.length==0)
        {
            //if (guideCodeStr.length==0) {
                UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选择日期" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
                [alert show];
           // }
            
        }
        else if(styleCodeStr.length==0)
            {
                   //if (guideCodeStr.length==0) {
                   UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选择类型" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
                   [alert show];
                   // }
                   
            }

        else if (_minGramTextField.text.length==0&&_maxGramTextField.text.length==0&&_minAmountTextField.text.length==0&&_maxAmountTextField.text.length==0)
        {
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选填克重或金额" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];

        }
        else if ([_maxGramTextField.text floatValue]<[_minGramTextField.text floatValue])
        {
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"最大克重需大于最小克重，请重新输入" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
            
        }
        

        else if ([_maxAmountTextField.text floatValue]<[_minAmountTextField.text floatValue])
        {
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"最大金额需大于最小金额，请重新输入" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];

        }
        

    }
    
}

-(void)imgBtnCLick:(UIButton *)sender
{
    imageBtnTag=sender.tag;
    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect viewFrame=_photoPickerViewContainer.frame;
         viewFrame.origin.y=0;
         _photoPickerViewContainer.frame=viewFrame;
     }completion:^(BOOL finished) {
         
         
     }];

}

#pragma 拍照选择照片协议方法
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    isLoad=YES;
    [UIApplication sharedApplication].statusBarHidden = NO;
    
    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    
   // NSData *data;
    
    if ([mediaType isEqualToString:@"public.image"]){
        
        //切忌不可直接使用originImage，因为这是没有经过格式化的图片数据，可能会导致选择的图片颠倒或是失真等现象的发生，从UIImagePickerControllerOriginalImage中的Origin可以看出，很原始，哈哈
        UIImage *originImage = [info objectForKey:UIImagePickerControllerOriginalImage];
        // NSLog(@"originImage.",originImage.size);
        //图片压缩，因为原图都是很大的，不必要传原图
       // UIImage *scaleImage = [self scaleImage:originImage toScale:1.0];
       //  UIImage *sampleImg=[self imageCompress:originImage];
        
        //以下这两步都是比较耗时的操作，最好开一个HUD提示用户，这样体验会好些，不至于阻塞界面
//       if (UIImagePNGRepresentation(scaleImage) == nil) {
            //将图片转换为JPG格式的二进制数据
         //   data = UIImageJPEGRepresentation(scaleImage, 1.0);
//        }
//        else {
////          //  将图片转换为PNG格式的二进制数据
//           data = UIImagePNGRepresentation(scaleImage);
//       }
        
       
        
        //将二进制数据生成UIImage
       // UIImage *image = [UIImage imageWithData:data];
        
       // NSData *imageData = UIImageJPEGRepresentation(image,0.01);
        //NSLog(@"imageData===%@",imageData);
        // UIImage *newImage = [UIImage imageWithData:imageData];
        
             //将图片传递给截取界面进行截取并设置回调方法（协议）
        CaptureViewController *captureView = [[CaptureViewController alloc] init];
        captureView.delegate = self;
        captureView.image = originImage;
        //隐藏UIImagePickerController本身的导航栏
        picker.navigationBar.hidden = NO;
        [picker pushViewController:captureView animated:YES];
        
    }
}

#pragma mark - 图片回传协议方法
-(void)passImage:(UIImage *)image
{
   
    UIImage *sampleImg=image;
    //NSLog(@"sampleImg===%f,%f",sampleImg.size.width,sampleImg.size.height);
    // isLoad=NO;
    
    CGRect frame=_addPictureButton.frame;
    
    UIImageView *getImageView=(UIImageView *)[_pictureView viewWithTag:imageBtnTag+100];
    if (getImageView==nil) {
        
        UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame=frame;
        btn.tag=5*btn.frame.origin.y/100+btn.frame.origin.x/117;
        [btn addTarget:self action:@selector(imgBtnCLick:) forControlEvents:UIControlEventTouchUpInside];
        
        UIImageView *sampleImageView=[[UIImageView alloc] initWithFrame:frame];
        sampleImageView.tag=5*sampleImageView.frame.origin.y/100+sampleImageView.frame.origin.x/117+100;
        //  sampleImageView.tag=9;
        [sampleImageView setImage:sampleImg];
        [_pictureView addSubview:sampleImageView];
        [_pictureView addSubview:btn];
        // [selectePictureArray addObject:sampleImageView];
        // NSLog(@"btn.tag===%d",btn.tag);
        //NSLog(@"sampleImageView.tag===%d",sampleImageView.tag);
        
        CGRect frame1=_addPictureButton.frame;
        frame1.origin.x=_addPictureButton.frame.origin.x+_addPictureButton.frame.size.width+27;
        _addPictureButton.frame=frame1;
        if (frame1.origin.x>484) {
            frame1.origin.x=16;
            frame1.origin.y=115;
            _addPictureButton.frame=frame1;
            
            CGRect viewFrame=_pictureView.frame;
            viewFrame.size.height=223;
            _pictureView.frame=viewFrame;
            
        }
        if (frame1.origin.x>484&&frame1.origin.y==115) {
            _addPictureButton.hidden=YES;
        }
        CGRect viewFrame0=_pictureViewLineLabel.frame;
        viewFrame0.origin.y= _pictureView.frame.size.height-1;
        _pictureViewLineLabel.frame=viewFrame0;
        CGRect viewFrame1=_remarkViewContainer.frame;
        viewFrame1.origin.y=_pictureView.frame.origin.y+_pictureView.frame.size.height+15;
        _remarkViewContainer.frame=viewFrame1;
        
        CGRect viewFrame2=_saveBtn.frame;
        viewFrame2.origin.y=_remarkViewContainer.frame.origin.y+_remarkViewContainer.frame.size.height+20;
        _saveBtn.frame=viewFrame2;
        
        [_addManagerRightScrollView setContentSize:CGSizeMake(0, _saveBtn.frame.origin.y+ _saveBtn.frame.size.height+10)];
        [_addManagerRightScrollView setScrollEnabled:YES];
    }
    else
    {
        getImageView.image=sampleImg;
    }
    imageBtnTag=10000;
    
}

#pragma mark- 缩放图片
-(UIImage *)scaleImage:(UIImage *)image toScale:(float)scaleSize
{
    UIGraphicsBeginImageContext(CGSizeMake(image.size.width*scaleSize,image.size.height*scaleSize));
    [image drawInRect:CGRectMake(0, 0, image.size.width * scaleSize, image.size.height *scaleSize)];
    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return scaledImage;
}

-(IBAction)albumOrCameraBtnClick:(UIButton *)sender
{
    CGRect viewFrame=_photoPickerViewContainer.frame;
    viewFrame.origin.y=768;
    _photoPickerViewContainer.frame=viewFrame;
    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    switch (sender.tag) {
        case 20000://Take picture
            
            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
                picker.sourceType = UIImagePickerControllerSourceTypeCamera;
                
            }else{
                NSLog(@"模拟器无法打开相机");
            }
            [self presentViewController:picker animated:YES completion:nil];
            break;
            
        case 20001://From album
            picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            [self presentViewController:picker animated:YES completion:nil];
            break;
            
        default:
            
            break;
    }
    
}

-(IBAction)cancelBtnClick:(id)sender
{
    // _CameraHelper.selectOrCancel=@"CANCEL";
    CGRect viewFrame=_photoPickerViewContainer.frame;
    viewFrame.origin.y=768;
    _photoPickerViewContainer.frame=viewFrame;
    // [_CameraHelper stopRunning];
    
    
}

-(NSString * )getSaveKey {
    NSDate *d = _datePickerView.date;
    int value = arc4random() % 1000;
    return [NSString stringWithFormat:@"/%d/%d/%d.jpg",[self getYear:d],[self getMonth:d],value];
   }

- (int)getYear:(NSDate *) date{
    NSDateFormatter *formatter =[[NSDateFormatter alloc] init];
    [formatter setTimeStyle:NSDateFormatterMediumStyle];
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSInteger unitFlags = NSYearCalendarUnit;
    NSDateComponents *comps = [calendar components:unitFlags fromDate:date];
    int year=[comps year];
    return year;
}

- (int)getMonth:(NSDate *) date{
    NSDateFormatter *formatter =[[NSDateFormatter alloc] init];
    [formatter setTimeStyle:NSDateFormatterMediumStyle];
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSInteger unitFlags = NSMonthCalendarUnit;
    NSDateComponents *comps = [calendar components:unitFlags fromDate:date];
    int month = [comps month];
    return month;
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
   
    [self dismissViewControllerAnimated:NO completion:^{
      
        CGRect viewFrame=_addManagerViewContainer.frame;
        viewFrame.origin.y=0;
        _addManagerViewContainer.frame=viewFrame;
    }];
   
}
-(UIImage *)imageCompress:(UIImage *)image
{
    UIImage *comImage=image;
    NSData * sendImageData = UIImageJPEGRepresentation(comImage, 1.0);
    NSUInteger sizeOrigin = [sendImageData length];
    NSUInteger sizeOriginKB = sizeOrigin / 1024;
    
    if (sizeOriginKB >100) {
        float a = 100.0000;
        float b = (float)sizeOriginKB;
        float q = sqrtf(a / b);
        
        CGSize sizeImage = [comImage size];
        CGFloat widthSmall = sizeImage.width * q;
        CGFloat heighSmall = sizeImage.height * q;
        CGSize sizeImageSmall = CGSizeMake(widthSmall, heighSmall);
        
        UIGraphicsBeginImageContext(sizeImageSmall);
        CGRect smallImageRect = CGRectMake(0, 0, sizeImageSmall.width, sizeImageSmall.height);
        [image drawInRect:smallImageRect];
        UIImage *smallImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        
        NSData *dataImage = UIImageJPEGRepresentation(smallImage, 1.0);
        sendImageData = dataImage;
        
        comImage= smallImage;
        // [_imageview1.image retain];
    }
    return comImage;
}
- (void)textViewDidChange:(UITextView *)textView
{
    if (textView.text.length == 0) {
        _textViewImageView.hidden=NO;
        _textViewLabel.hidden=NO;
        
    }
    else
    {
        _textViewImageView.hidden=YES;
        _textViewLabel.hidden=YES;
        
    }
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    [UIView animateWithDuration:0.3 animations:^{
        CGRect viewFrame=_addManagerViewContainer.frame;
        viewFrame.origin.y=-330;
        _addManagerViewContainer.frame=viewFrame;
    } completion:^(BOOL finished){
        
    }];
    
    
    return YES;
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
     [_addManagerRightScrollView setContentOffset:CGPointMake(0, 0)];
    [UIView animateWithDuration:0.3 animations:^{
        CGRect viewFrame=_addManagerViewContainer.frame;
        viewFrame.origin.y=0;
        _addManagerViewContainer.frame=viewFrame;
    } completion:^(BOOL finished){
        
    }];
    
    
}
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    if ( textField ==_searchProductTextField) {
        return YES;
    }

    NSCharacterSet *cs;
    cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS]invertedSet];
    
    NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""];
    
    BOOL canChange = [string isEqualToString:filtered];
    
    return canChange;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
